<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                 label-width="68px">
            <el-form-item label="村社:" prop="communityId">
                <el-select v-model="queryParams.communityId" placeholder="请选择对应的村社或村" clearable>
                    <el-option
                        v-for="community in communityList"
                        :key="community.communityId"
                        :label="community.communityName"
                        :value="community.communityId"
                    ></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="户主:" prop="isHead">
                <el-select v-model="queryParams.isHead" placeholder="请选择是否户主" clearable>
                    <el-option
                        v-for="dict in dict.type.biz_yes_no"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="网格员:" prop="isGrid" >
                <el-select v-model="queryParams.isGrid" placeholder="是否是网格员" clearable>
                    <el-option
                        v-for="dict in dict.type.biz_yes_no"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="村委:" prop="isCommittee">
                <el-select v-model="queryParams.isCommittee" placeholder="是否是村居委" clearable>
                    <el-option
                        v-for="dict in dict.type.biz_yes_no"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="党员:" prop="isParty">
                <el-select v-model="queryParams.isParty" placeholder="是否是党员"clearable>
                    <el-option
                        v-for="dict in dict.type.biz_yes_no"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="姓名:" prop="peopleName">
                <el-input
                    v-model="queryParams.peopleName"
                    placeholder="请输入姓名"
                    clearable
                    @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <el-form-item label="身份证:" prop="peopleCard">
                <el-input
                    v-model="queryParams.peopleCard"
                    placeholder="请输入身份证"
                    clearable
                    @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <el-form-item label="手机:" prop="peopleMobile">
                <el-input
                    v-model="queryParams.peopleMobile"
                    placeholder="请输入手机"
                    clearable
                    @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <el-form-item label="状态:" prop="status">
                <el-select v-model="queryParams.status" placeholder="居民状态"  clearable>
                    <el-option
                        v-for="dict in dict.type.people_status"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="住址:" prop="peopleAddress">
              <el-input
                  v-model="queryParams.peopleAddress"
                  placeholder="请输入住址"
                  clearable
                  @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button
                    type="danger"
                    plain
                    icon="el-icon-plus"
                    size="mini"
                    @click="handleAdd(1)"
                    v-hasPermi="['organization:people:add']"
                >新增户主
                </el-button>
            </el-col>
            <el-col :span="1.5" style="display: none">
                <el-button
                    type="warning"
                    plain
                    icon="el-icon-download"
                    size="mini"
                    @click="handleExport"
                    v-hasPermi="['organization:people:export']"
                >导出
                </el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button
                    type="primary"
                    plain
                    icon="el-icon-upload2"
                    size="mini"
                    @click="handleImport"
                    v-hasPermi="['organization:people:import']"
                >导入村居民
                </el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button
                    type="primary"
                    plain
                    icon="el-icon-upload2"
                    size="mini"
                    @click="handleImportGrid"
                    v-hasPermi="['organization:people:import']"
                >导入网格员
                </el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="peopleList" @selection-change="handleSelectionChange" border >
            <el-table-column type="selection" align="center"/>
            <el-table-column label="身份证" align="center" prop="peopleCard" width="200">
                <template slot-scope="scope">{{scope.row.peopleCard}}</template>
            </el-table-column>
            <el-table-column label="姓名" align="center" prop="peopleName"/>
            <el-table-column label="手机" align="center" prop="peopleMobile" width="150">
                <template slot-scope="scope">{{scope.row.peopleMobile}}</template>
            </el-table-column>
            <el-table-column label="户主" align="center" prop="isHead">
                <template slot-scope="scope">
                    <el-tag type="danger" v-if="scope.row.isHead==1">是</el-tag>
                    <el-tag v-if="scope.row.isHead==0">否</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="性别" align="center" prop="peopleSex">
                <template slot-scope="scope">
                    <span v-if="scope.row.peopleSex==1">女</span>
                    <span v-if="scope.row.peopleSex==2">男</span>
                </template>
            </el-table-column>
            <el-table-column label="出生年月" align="center" prop="peopleBirth" width="150"/>
            <el-table-column label="住址" align="center" prop="peopleAddress" width="150"/>
            <el-table-column label="村社" align="center" prop="communityName"/>
            <el-table-column label="网格" align="center" prop="gridName"/>
            <el-table-column label="网格员" align="center" prop="isGrid" width="150">
                <template slot-scope="scope">
                    <span v-if="scope.row.isGrid==0">否</span>
                    <el-tag type="danger" v-if="scope.row.isGrid==1">是</el-tag>
                </template>
            </el-table-column>

            <el-table-column label="运营网格" align="center" prop="isGrid" width="180">
                <template slot-scope="scope">
                    <el-tag type="danger" v-if="scope.row.isGrid==1">{{scope.row.gridString}}</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="党员" align="center" prop="isParty">
                <template slot-scope="scope">
                    <el-switch
                        v-model="scope.row.isParty"
                        :active-value="1"
                        :inactive-value="0"
                        @change="handleIsPartyChange(scope.row)"
                    ></el-switch>
                </template>
            </el-table-column>
            <el-table-column label="村居委" align="center" prop="isCommittee">
                <template slot-scope="scope">
                    <span v-if="scope.row.isCommittee==0">否</span>
                    <span v-if="scope.row.isCommittee==1">是</span>
                </template>
            </el-table-column>
            <el-table-column label="状态" align="center" prop="status">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.people_status" :value="scope.row.status"/>
                </template>
                <template slot-scope="scope">
                    <el-tag type="danger" v-if="scope.row.status==-1">未绑定身份证</el-tag>
                    <el-tag type="warning" v-if="scope.row.status==0">待审核</el-tag>
                    <el-tag type="success" v-if="scope.row.status==1">审核通过</el-tag>
                    <el-tag type="error" v-if="scope.row.status==2">审核不通过</el-tag>
                    <el-tag type="info" v-if="scope.row.status==3">待登记用户信息</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center"  fixed="right"  width="150">
                <template slot-scope="scope">

                  <el-button
                        size="mini"
                        type="text"
                        icon="el-icon-edit"
                        @click="handleUpdate(scope.row)"
                        v-hasPermi="['organization:people:edit']"
                        v-if="scope.row.status=='1'"
                    >修改
                    </el-button>
                    <el-button
                        size="mini"
                        type="text"
                        icon="el-icon-thumb"
                        @click="handleAudit(scope.row)"
                        v-hasPermi="['organization:people:edit']"
                        v-if="scope.row.status=='0'"
                    >审核居民
                    </el-button>

                    <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)"
                                 v-hasPermi="['system:user:resetPwd', 'organization:people:edit']" v-if="scope.row.status=='1'">
                        <el-button size="mini" type="text" icon="el-icon-d-arrow-right">更多</el-button>
                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item command="handleSetHeadCard" icon="el-icon-circle-check"
                                              v-hasPermi="['organization:people:edit']" v-if="scope.row.status=='1' && scope.row.headCard==''">设为户主
                            </el-dropdown-item>
                            <el-dropdown-item command="handleFamily" icon="el-icon-circle-check"
                                              v-hasPermi="['organization:people:add']" v-if="scope.row.status=='1' && scope.row.headCard!=''">查看家庭成员
                            </el-dropdown-item>
                            <el-dropdown-item command="handleAdds" icon="el-icon-circle-check"
                                              v-hasPermi="['organization:people:add']" v-if="scope.row.status=='1' && scope.row.isHead=='1'">添加家庭成员
                            </el-dropdown-item>
                            <el-dropdown-item command="handleFamilyScore" icon="el-icon-circle-check"
                                              v-hasPermi="['organization:people:edit']" v-if="scope.row.status=='1' && scope.row.headCard!=''">查看家庭积分
                            </el-dropdown-item>

                            <el-dropdown-item command="handleCancelGird" icon="el-icon-circle-check"
                                              v-hasPermi="['organization:people:edit']" v-if="scope.row.isGrid=='1'">取消网格员
                            </el-dropdown-item>
                            <el-dropdown-item command="handleGird" icon="el-icon-circle-check"
                                              v-hasPermi="['organization:people:edit']" v-if="scope.row.isGrid=='0'">设置网格员
                            </el-dropdown-item>
                            <el-dropdown-item command="handleResetWx" icon="el-icon-circle-check"
                                              v-hasPermi="['organization:people:edit']"  v-if="scope.row.openId && scope.row.isGrid=='1'">解绑微信网格员
                            </el-dropdown-item>
                            <el-dropdown-item command="handleCommonResetWx" icon="el-icon-circle-check"
                                              v-hasPermi="['organization:people:edit']"  v-if="scope.row.openId && scope.row.isGrid=='0'">解绑村居民微信
                            </el-dropdown-item>

                            <el-dropdown-item command="generatePeopleCard" icon="el-icon-circle-check"
                                              v-hasPermi="['organization:people:edit']" v-if="scope.row.status=='1'">下载村民卡牌
                            </el-dropdown-item>
                            <el-dropdown-item command="modifyCommunity" icon="el-icon-circle-check"
                                              v-hasPermi="['organization:people:edit']" v-if="scope.row.status=='1'">变更社区
                            </el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                </template>
            </el-table-column>
        </el-table>

        <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
        />

        <!-- 添加或修改村民对话框 -->
        <el-dialog  :visible.sync="open" width="700px" append-to-body>
            <div slot="title" class="dialog-title">
                <span class="title-text" v-html="title"></span>
                <div class="button-right">
                    <span class="title-close" @click="cancel"></span>
                </div>
            </div>
            <el-form ref="form" :model="form" :rules="rules" label-width="120px">

                <el-form-item label="村居委:" prop="isCommittee">
                    <el-radio-group v-model="form.isCommittee">
                        <el-radio :label="ifv.key" :key="ifv.key" v-for="ifv in ifCommittee">{{ifv.label}}</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="村社:" prop="communityId">
                    <el-select v-model="form.communityId" placeholder="请选择对应的村社" clearable @change="changeGrid">
                        <el-option
                            v-for="community in communityList"
                            :key="community.communityId"
                            :label="community.communityName"
                            :value="community.communityId"
                        ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="网格:" prop="gridId">
                    <el-select v-model="form.gridId" placeholder="请选择对应的网格" @change="selectGrid">
                        <el-option
                            v-for="grid in optionsGrids"
                            :key="grid.gridId"
                            :label="grid.gridName"
                            :value="grid.gridId"
                        ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="身份证号:" prop="peopleCard" >
                    <el-input v-model="form.peopleCard" placeholder="请输入身份证"/>
                </el-form-item>
                <el-form-item label="姓名:" prop="peopleName">
                    <el-input v-model="form.peopleName" placeholder="请输入姓名"/>
                </el-form-item>

                <el-form-item label="手机:" prop="peopleMobile">
                    <el-input v-model="form.peopleMobile" placeholder="请输入手机" />
                </el-form-item>
                <el-form-item label="住址:" prop="peopleAddress">
                  <el-input v-model="form.peopleAddress" placeholder="请输入住址"/>
                </el-form-item>

                <el-form-item label="备注:" prop="remark">
                    <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"/>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="danger" @click="submitForm" v-if="form.isHead==1">
                    <span v-if="form.peopleId>0">更新户主信息</span>
                    <span v-if="form.peopleId==undefined">新增户主信息</span>
                </el-button>
                <el-button type="primary" @click="submitForm" v-if="form.isHead==0">
                    <span v-if="form.peopleId>0">更新居民信息</span>
                    <span v-if="form.peopleId==undefined">新增家庭成员信息</span>
                </el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
        <!--修改用户信息-->
        <el-dialog  :visible.sync="modifyOpen" width="700px" append-to-body>
            <div slot="title" class="dialog-title">
                <span class="title-text" v-html="title"></span>
                <div class="button-right">
                    <span class="title-close" @click="cancel"></span>
                </div>
            </div>
            <el-form ref="form" :model="form" :rules="rules" label-width="120px">

                <el-form-item label="村居委:" prop="isCommittee">
                    <el-radio-group v-model="form.isCommittee">
                        <el-radio :label="ifv.key" :key="ifv.key" v-for="ifv in ifCommittee">{{ifv.label}}</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="村社:" prop="communityId">
                    <el-select v-model="form.communityId" placeholder="请选择对应的村社" clearable @change="changeGrid" disabled>
                        <el-option
                            v-for="community in communityList"
                            :key="community.communityId"
                            :label="community.communityName"
                            :value="community.communityId"
                        ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="网格:" prop="gridId">
                    <el-select v-model="form.gridId" placeholder="请选择对应的网格" @change="selectGrid">
                        <el-option
                            v-for="grid in optionsGrids"
                            :key="grid.gridId"
                            :label="grid.gridName"
                            :value="grid.gridId"
                        ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="身份证号:" prop="peopleCard" >
                    <el-input v-model="form.peopleCard" placeholder="请输入身份证" disabled/>
                </el-form-item>
                <el-form-item label="姓名:" prop="peopleName">
                    <el-input v-model="form.peopleName" placeholder="请输入姓名"/>
                </el-form-item>

                <el-form-item label="手机:" prop="peopleMobile">
                    <el-input v-model="form.peopleMobile" placeholder="请输入手机" />
                </el-form-item>
                <el-form-item label="住址:" prop="peopleAddress">
                    <el-input v-model="form.peopleAddress" placeholder="请输入住址"/>
                </el-form-item>

                <el-form-item label="备注:" prop="remark">
                    <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"/>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="danger" @click="submitForm" v-if="form.isHead==1">
                    <span v-if="form.peopleId>0">更新户主信息</span>
                    <span v-if="form.peopleId==undefined">新增户主信息</span>
                </el-button>
                <el-button type="primary" @click="submitForm" v-if="form.isHead==0">
                    <span v-if="form.peopleId>0">更新居民信息</span>
                    <span v-if="form.peopleId==undefined">新增家庭成员信息</span>
                </el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
        <!--修改用户信息-->
        <!--新增家庭成员-->
        <el-dialog  :visible.sync="addUser" width="700px" append-to-body>
            <div slot="title" class="dialog-title">
                <span class="title-text" v-html="title"></span>
                <div class="button-right">
                    <span class="title-close" @click="cancel"></span>
                </div>
            </div>
            <el-form ref="form" :model="form" :rules="rules" label-width="120px">

                <el-form-item label="村居委:" prop="isCommittee">
                    <el-radio-group v-model="form.isCommittee">
                        <el-radio :label="ifv.key" :key="ifv.key" v-for="ifv in ifCommittee">{{ifv.label}}</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="村社:" prop="communityId">
                    <el-select v-model="form.communityId" placeholder="请选择对应的村社" clearable @change="changeGrid">
                        <el-option
                            v-for="community in communityList"
                            :key="community.communityId"
                            :label="community.communityName"
                            :value="community.communityId"
                        ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="网格:" prop="gridId">
                    <el-select v-model="form.gridId" placeholder="请选择对应的网格" @change="selectGrid" clearable>
                        <el-option
                            v-for="grid in optionsGrids"
                            :key="grid.gridId"
                            :label="grid.gridName"
                            :value="grid.gridId"
                        ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="身份证号:" prop="peopleCard" >
                    <el-input v-model="form.peopleCard" placeholder="请输入身份证"/>
                </el-form-item>
                <el-form-item label="姓名:" prop="peopleName">
                    <el-input v-model="form.peopleName" placeholder="请输入姓名"/>
                </el-form-item>

                <el-form-item label="手机:" prop="peopleMobile">
                    <el-input v-model="form.peopleMobile" placeholder="请输入手机" />
                </el-form-item>
                <el-form-item label="住址:" prop="peopleAddress">
                    <el-input v-model="form.peopleAddress" placeholder="请输入住址"/>
                </el-form-item>

                <el-form-item label="备注:" prop="remark">
                    <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"/>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="danger" @click="submitForm" v-if="form.isHead==1">
                    <span v-if="form.peopleId>0">更新户主信息</span>
                    <span v-if="form.peopleId==undefined">新增户主信息</span>
                </el-button>
                <el-button type="primary" @click="submitForm" v-if="form.isHead==0">
                    <span v-if="form.peopleId>0">更新居民信息</span>
                    <span v-if="form.peopleId==undefined">新增家庭成员信息</span>
                </el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
        <!--新增家庭成员-->
        <!--变更社区-->
        <el-dialog  :visible.sync="modifyCommunityDiv" width="700px" append-to-body>
            <div slot="title" class="dialog-title">
                <span class="title-text" v-html="title"></span>
                <div class="button-right">
                    <span class="title-close" @click="cancel"></span>
                </div>
            </div>
            <el-form ref="form" :model="form" :rules="rules" label-width="120px">
                <div>
                    <span style="color: #ff0000;text-align: center;margin-left: 80px;">-户主变更后，将从原家庭中随机选取新用户担任户主</span>
                    <br/>
                    <span style="color: #ff0000;text-align: center;margin-left: 80px;margin-bottom: 10px">-非户主变更后将从原家庭中删除，并独立成户</span>
                </div>
                <el-form-item label="身份证号:" prop="peopleCard" >
                    <el-input v-model="form.peopleCard" placeholder="请输入身份证" disabled/>
                </el-form-item>
                <el-form-item label="姓名:" prop="peopleName">
                    <el-input v-model="form.peopleName" placeholder="请输入姓名" disabled/>
                </el-form-item>
                <el-form-item label="村社:" prop="communityId">
                    <el-select v-model="form.communityId" placeholder="请选择对应的村社" clearable @change="changeGrid">
                        <el-option
                            v-for="community in communityList"
                            :key="community.communityId"
                            :label="community.communityName"
                            :value="community.communityId"
                        ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="网格:" prop="gridId">
                    <el-select v-model="form.gridId" placeholder="请选择对应的网格" @change="selectGrid" clearable>
                        <el-option
                            v-for="grid in optionsGrids"
                            :key="grid.gridId"
                            :label="grid.gridName"
                            :value="grid.gridId"
                        ></el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="danger" @click="doModifyCommunity">
                   变更社区信息
                </el-button>

                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
        <!--变更社区-->

        <!-- 用户导入对话框 -->
        <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px">
            <el-upload
                ref="upload"
                :limit="1"
                accept=".xlsx, .xls"
                :headers="upload.headers"
                :action="upload.url + '?updateSupport=' + upload.updateSupport"
                :disabled="upload.isUploading"
                :on-progress="handleFileUploadProgress"
                :on-success="handleFileSuccess"
                :auto-upload="false"
                drag
            >
                <i class="el-icon-upload"></i>
                <div class="el-upload__text">
                    将文件拖到此处，或
                    <em>点击上传</em>
                </div>
                <div class="el-upload__tip" slot="tip">
                    <el-link type="info" style="font-size:12px;margin-right:5px;" @click="importTemplate(1)">下载居民模板</el-link>
                    <el-link type="info" style="font-size:12px" @click="importTemplate(2)">下载村民模板</el-link>
                </div>
                <div class="el-upload__tip" style="color:red" slot="tip">提示：仅允许导入“xls”或“xlsx”格式文件！</div>
            </el-upload>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitFileForm" v-if="!upload.isUploading">确 定</el-button>
                <el-button type="primary" v-if="upload.isUploading">处理中</el-button>
                <el-button @click="upload.open = false">取 消</el-button>
            </div>
        </el-dialog>
        <el-dialog :title="upload.title" :visible.sync="upload.openGrid" width="400px">
            <el-upload
                ref="gridUpload"
                :limit="1"
                accept=".xlsx, .xls"
                :headers="upload.headers"
                :action="upload.gridUrl + '?updateSupport=' + upload.updateSupport"
                :disabled="upload.isUploading"
                :on-progress="handleFileUploadProgress"
                :on-success="handleGridFileSuccess"
                :auto-upload="false"
                drag
            >
                <i class="el-icon-upload"></i>
                <div class="el-upload__text">
                    将文件拖到此处，或
                    <em>点击上传</em>
                </div>
                <div class="el-upload__tip" slot="tip">
                    <el-link type="info" style="font-size:12px;margin-right:5px;" @click="importTemplate(4)">下载社区网格员模版</el-link>
                    <el-link type="info" style="font-size:12px;margin-right:5px;" @click="importTemplate(3)">下载村网格员模版</el-link>
                </div>
                <div class="el-upload__tip" style="color:red" slot="tip">提示：仅允许导入“xls”或“xlsx”格式文件！</div>
            </el-upload>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="gridSubmitFileForm" v-if="!upload.isUploading">确 定</el-button>
                <el-button type="primary" v-if="upload.isUploading">处理中</el-button>
                <el-button @click="upload.openGrid = false">取 消</el-button>
            </div>
        </el-dialog>

        <el-dialog title="家庭成员" :visible.sync="familyVisible" width="1000px">
            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                    <el-button
                        type="danger"
                        plain
                        icon="el-icon-plus"
                        size="mini"
                        @click="handleNewAdd()"
                        v-hasPermi="['organization:people:add']"
                    >迁入新成员
                    </el-button>
                </el-col>
            </el-row>

            <el-table :data="familys" border>
                <el-table-column label="身份证" align="center" prop="peopleCard" width="200"/>
                <el-table-column label="姓名" align="center" prop="peopleName"/>
                <el-table-column label="手机" align="center" prop="peopleMobile" width="150">
                    <template slot-scope="scope">{{splitPhone(scope.row.peopleMobile)}}</template>
                </el-table-column>
                <el-table-column label="户主" align="center" prop="isHead">
                    <template slot-scope="scope">
                        <el-tag type="danger" v-if="scope.row.isHead==1">是</el-tag>
                        <el-tag v-if="scope.row.isHead==0">否</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="性别" align="center" prop="peopleSex">
                    <template slot-scope="scope">
                        <span v-if="scope.row.peopleSex==1">女</span>
                        <span v-if="scope.row.peopleSex==2">男</span>
                    </template>
                </el-table-column>
                <el-table-column label="出生年月" align="center" prop="peopleBirth"/>
                <el-table-column label="住址" align="center" prop="peopleAddress"/>
                <el-table-column label="网格员" align="center" prop="isGrid">
                    <template slot-scope="scope">
                        <span v-if="scope.row.isGrid==0">否</span>
                        <span v-if="scope.row.isGrid==1">是</span>
                    </template>
                </el-table-column>
                <el-table-column label="村居委" align="center" prop="isCommittee">
                    <template slot-scope="scope">
                        <span v-if="scope.row.isCommittee==0">否</span>
                        <span v-if="scope.row.isCommittee==1">是</span>
                    </template>
                </el-table-column>
                <el-table-column label="状态" align="center" prop="status">
                    <template slot-scope="scope">
                        <dict-tag :options="dict.type.people_status" :value="scope.row.status"/>
                    </template>
                    <template slot-scope="scope">
                        <el-tag type="danger" v-if="scope.row.status==-1">未绑定身份证</el-tag>
                        <el-tag type="warning" v-if="scope.row.status==0">待审核</el-tag>
                        <el-tag type="success" v-if="scope.row.status==1">审核通过</el-tag>
                        <el-tag type="error" v-if="scope.row.status==2">审核不通过</el-tag>
                        <el-tag type="info" v-if="scope.row.status==3">待登记用户信息</el-tag>
                    </template>
                </el-table-column>
            </el-table>
        </el-dialog>
        <!-- 添加或修改角色配置对话框 -->
        <el-dialog :visible.sync="girdVisible" width="500px" append-to-body>
            <div slot="title" class="dialog-title">
                <span class="title-text" v-html="titleGird"></span>
                <div class="button-right">
                    <span class="title-close" @click="cancel"></span>
                </div>
            </div>
            <el-form ref="girdForm" :model="girdForm"  label-width="100px">
                <el-form-item label="所在村社：" prop="community" label-width="100px">
                   {{girdForm.communityName}}
                </el-form-item>
                <el-form-item label="负责的网格：" label-width="100px">
                    <el-tree
                        style="overflow:auto;width: 80%;max-height:300px"
                        class="tree-border"
                        :data="girdData"
                        show-checkbox
                        ref="girdRef"
                        node-key="id"
                        :default-expand-all="true"
                        empty-text="加载中，请稍候"
                    ></el-tree>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitGirdForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
        <!-- 添加或修改村民对话框 -->
        <el-dialog  :visible.sync="toFamilyOpen" width="1000px" append-to-body>
            <div slot="title" class="dialog-title">
                <span class="title-text" v-html="title"></span>
                <div class="button-right">
                    <span class="title-close" @click="cancel"></span>
                </div>
            </div>
            <el-form ref="form" :model="form" :rules="rules" label-width="120px">
                <el-form-item label="身份证号:" prop="peopleCard">
                    <el-input v-model="form.peopleCard" placeholder="请输入身份证" style="width:400px;margin-right: 10px"/>
                    <el-button  type="primary"@click="searchPeople">搜索</el-button>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button  type="primary" @click="ingoing">
                    确认迁入
                </el-button>
                <el-button @click="closeFalimyOpen">取 消</el-button>
            </div>
            <el-table v-if="headOptions" :data="headOptions"  @selection-change="handleSelectionChange" border >
                <el-table-column type="selection" align="center"/>
                <el-table-column label="身份证" align="center" prop="peopleCard" width="200">
                    <template slot-scope="scope">{{scope.row.peopleCard}}</template>
                </el-table-column>
                <el-table-column label="姓名" align="center" prop="peopleName"/>
                <el-table-column label="手机" align="center" prop="peopleMobile" width="150">
                    <template slot-scope="scope">{{scope.row.peopleMobile}}</template>
                </el-table-column>
                <el-table-column label="户主" align="center" prop="isHead">
                    <template slot-scope="scope">
                        <el-tag type="danger" v-if="scope.row.isHead==1">是</el-tag>
                        <el-tag v-if="scope.row.isHead==0">否</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="性别" align="center" prop="peopleSex">
                    <template slot-scope="scope">
                        <span v-if="scope.row.peopleSex==1">女</span>
                        <span v-if="scope.row.peopleSex==2">男</span>
                    </template>
                </el-table-column>
                <el-table-column label="出生年月" align="center" prop="peopleBirth" width="150"/>
                <el-table-column label="住址" align="center" prop="peopleAddress" width="150"/>
                <el-table-column label="村社" align="center" prop="communityName"/>
                <el-table-column label="网格" align="center" prop="gridName"/>
                <el-table-column label="网格员" align="center" prop="isGrid" width="150">
                    <template slot-scope="scope">
                        <span v-if="scope.row.isGrid==0">否</span>
                        <el-tag type="danger" v-if="scope.row.isGrid==1">是</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="状态" align="center" prop="status">
                    <template slot-scope="scope">
                        <dict-tag :options="dict.type.people_status" :value="scope.row.status"/>
                    </template>
                    <template slot-scope="scope">
                        <el-tag type="danger" v-if="scope.row.status==-1">未绑定身份证</el-tag>
                        <el-tag type="warning" v-if="scope.row.status==0">待审核</el-tag>
                        <el-tag type="success" v-if="scope.row.status==1">审核通过</el-tag>
                        <el-tag type="error" v-if="scope.row.status==2">审核不通过</el-tag>
                        <el-tag type="info" v-if="scope.row.status==3">待登记用户信息</el-tag>
                    </template>
                </el-table-column>
            </el-table>

        </el-dialog>
        <!-- 解绑并绑定新号码 -->
        <el-dialog  :visible.sync="restWxOpen"  width="700px" append-to-body>
            <div slot="title" class="dialog-title">
                <span class="title-text" v-html="title"></span>
                <div class="button-right">
                    <span class="title-close" @click="cancel"></span>
                </div>
            </div>
            <el-form ref="restWxForm" :model="form"  :rules="wxRules" label-width="120px">
                <el-form-item label="姓名:" prop="peopleName">
                    <el-input v-model="form.peopleName" placeholder="请姓名" clearable/>
                </el-form-item>
                <el-form-item label="身份证号:" prop="peopleCard">
                    <el-input v-model="form.peopleCard" placeholder="请输入身份证" clearable/>
                     <span>若是网格员可以设置字母+数字 LTSQWGY01</span>
                </el-form-item>

            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitRestWxForm">
                    解绑并设置新身份证号码
                </el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import {
    listPeople,
    getPeople,
    delPeople,
    addPeople,
    updatePeople,
    auditPeople,
    setHeadCard,
    getFamilyPeople, setGird, changeIsParty, setIngoing, resetPeopleWx, doSetCommunity, resetCommonPeopleWx
} from "@/api/organization/people";
import {listGrid} from "@/api/organization/grid";
import {listCommunity} from "@/api/organization/community";
import {girdList, girdLists,} from "@/api/organization/grid";

import {getToken} from "@/utils/auth";
import {hideCardNo, isIdCard, isPhone, splitPhone} from "@/utils/ruoyi";
import router from "@/router";
// 权限判断函数
import {checkPermi, checkRole} from "@/utils/permission";

export default {
    name: "People",
    dicts:['biz_yes_no','people_status'],
    data() {
        return {
            restWxOpen:false,
            currentFamily:'',
            newHead:'',
            headOptions:[],
            girdData:[],
            titleGird:'',
            girdVisible:false,
            familyVisible:false,
            gridCheckbox:[{'label': '设置网格员', 'key': '1'},{'label': '取消网格员', 'key': '2'}],
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 村民表格数据
            peopleList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            addUser: false,
            modifyCommunityDiv: false,
            modifyOpen: false,
            toFamilyOpen:false,
            ifHead:[{'label': '否', 'key': '0'},{'label': '是', 'key': '1'}],
            ifGrid:[{'label': '否', 'key': '0'},{'label': '是', 'key': '1'}],
            ifCommittee:[{'label': '否', 'key': '0'},{'label': '是', 'key': '1'}],
            optionsGrids:[],
            commonQueryVars: {
                pageNum: 1,
                pageSize: 100,
            },
            gridVars:{
                communityId:"",
                pageNum:1,
                pageSize:100
            },
            communityList: [],
            showHead:false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                openId: null,
                openNickname: null,
                isHead: null,
                headId: null,
                peopleName: null,
                peopleMobile: null,
                peopleCard: null,
                peopleSex: null,
                peopleBirth: null,
                peopleAddress: null,
                communityId: null,
                gridId: null,
                isParty: null,
                isGrid: "",
                isCommittee: null,
                status: null,
            },
            familyVars:{"headCard":"","peopleId":""},
            familys:[],
            // 查询参数
            commonVars: {
                pageNum: 1,
                pageSize: 100
            },
            girdForm:{},
            // 表单参数
            form: {},
            // 表单校验
            rules: {
                peopleName: [
                    {required: true, message: "姓名不能为空", trigger: "blur"}
                ],
                peopleMobile: [
                    {required: true, message: "手机不能为空", trigger: "blur"}
                ],
                peopleCard: [
                    {required: true, message: "身份证不能为空", trigger: "blur"}
                ],
                communityId: [{required: true, message: "所属村社或村不能空", trigger: "blur"}],
                gridId: [{required: true, message: "所属网格不能空", trigger: "blur"}],
            },
            wxRules: {
                peopleName: [
                    {required: true, message: "姓名不能为空", trigger: "blur"}
                ],
                peopleCard: [
                    {required: true, message: "新身份证不能为空", trigger: "blur"}
                ]
            },
            upload: {
                // 是否显示弹出层（用户导入）
                open: false,
                openGrid: false,
                // 弹出层标题（用户导入）
                title: "",
                // 是否禁用上传
                isUploading: false,
                // 是否更新已经存在的用户数据
                updateSupport: 0,
                // 设置上传的请求头部
                headers: {Authorization: "Bearer " + getToken()},
                // 上传的地址
                url: process.env.VUE_APP_BASE_API + "/organization/people/importData",
                gridUrl: process.env.VUE_APP_BASE_API + "/organization/people/importGridData"
            },
            ingoingVar: {}
        };
    },
    created() {
        this.getList();
        this.getCommunityList();
    },
    methods: {
        hideCardNo,
        splitPhone,
        checkPermi,

        // 更多操作触发
        handleCommand(command, row) {
            switch (command) {
                //添加家庭成员
                case "handleAdds":
                    this.handleAdds(row);
                    break;
                //查看家庭成员
                case "handleFamily":
                    this.handleFamily(row);
                    break;
                //查看家庭积分
                case "handleFamilyScore":
                    this.handleFamilyScore(row);
                    break
                //卡牌
                case "generatePeopleCard":
                    this.generatePeopleCard(row);
                    break;
                //设置户主
                case "handleSetHeadCard":
                    this.handleSetHeadCard(row);
                    break;
                //设置网格员
                case "handleGird":
                    this.handleGird(row);
                    break;
                case "handleCancelGird":
                    this.handleCancelGird(row);
                    break;
                case "handleResetWx":
                    this.handleResetWx(row);
                    break;
                case "handleCommonResetWx":
                    this.handleCommonResetWx(row);
                    break;
                case "modifyCommunity":
                    this.modifyCommunity(row);
                default:
                    break;
            }
        },
        closeFalimyOpen(){
            this.toFamilyOpen = false
            this.headOptions=[]
        },
        handleNewAdd() {//迁入新成员
            this.reset();
            this.title = "查找新成员:<b><font color='red'> 居民迁移积分不做合并！</font></b>";
            this.toFamilyOpen = true;
        },
        searchPeople(query) {
            listPeople(this.form).then(rep => {
                this.headOptions = rep.rows;
            })
        },
        //嵌入
        ingoing() {
            if (this.ids.length==0) {
                this.$modal.msgError("请先选择要迁入的成员");
                return;
            }
            var currentPeople ={};
            this.headOptions.forEach(item => {
                if (item.peopleId == this.ids) {
                    currentPeople.peopleId = item.peopleId;
                    currentPeople.peopleName = item.peopleName;
                    currentPeople.peopleCard = item.peopleCard;
                }
            })
            var text = "确认要将当前居民："+currentPeople.peopleName+"，迁移到户主："+this.currentFamily.peopleName+"名下?";
            this.ingoingVar.peopleId = currentPeople.peopleId;
            this.ingoingVar.newPeopleId = this.currentFamily.peopleId;
            const  data = this.ingoingVar;
            this.$modal.confirm(text).then(function () {
                setIngoing(data);
                this.toFamilyOpen = false;
                this.handleFamily(this.currentFamily);
                this.$modal.msgSuccess("迁入成功");
            }).then(() => {


            }).catch(() => { //alert("33")
            });
        },
        //取消网格员
        handleCancelGird:function (row) {
            this.girdForm.communityId = row.communityId;
            this.girdForm.peopleId = row.peopleId;
            this.girdForm.isSetting = 0;
            const data = this.girdForm;
            this.$modal.confirm('确认取消' + row.peopleName + '的网格员资格?').then(function () {
                return setGird(data);
            }).then(() => {
                this.$modal.msgSuccess("取消网格员成功");
                this.getList();
            }).catch(() => { //alert("33")
            });

        },
        //设置
        handleGird(row) {
            console.log(row)
            // this.titleGird =  "蒋居民:<b><font color='red'> "+row.peopleName+"</font></b>设为网格员";
            this.titleGird = "蒋居民:<b><font color='red'> "+row.peopleName+"</font></b>设为网格员";
            this.girdVisible = true;
            this.girdForm.communityName = row.communityName;
            this.girdForm.communityId = row.communityId;
            this.girdForm.peopleId = row.peopleId;

            girdLists(row.communityId).then(res=>{
                this.girdData = res.data;
            });
        },
        //设置党员
        handleIsPartyChange(row) {
                let text = row.isParty == 1 ? "将"+row.peopleName+"设置党员" : "取消"+row.peopleName+"党员资格";
                this.$modal.confirm(text  + '？').then(function () {
                    return changeIsParty(row.peopleId, row.isParty);
                }).then(() => {
                    this.$modal.msgSuccess(text + "成功");
                }).catch(function () {
                    row.isParty = row.isParty === "0" ? "1" : "0";
                });
        },
        //设置网格员
        submitGirdForm() {
            console.log(this.$refs.girdRef.getCheckedNodes());
            console.log(this.$refs.girdRef.getCheckedKeys());
            // this.girdForm
            if (this.$refs.girdRef.getCheckedNodes().length==0) {
                this.$modal.alertError("请选择要管理的网格");
                return false;
            }
            this.girdForm.girds = this.$refs.girdRef.getCheckedNodes();
            this.girdForm.isSetting = 1;
            setGird(this.girdForm).then(response => {
                this.$modal.msgSuccess("设置成功");
                this.girdVisible = false;
                this.getList();
            });
        },
        getCommunityList(){
            listCommunity(this.commonVars).then(response=>{
                this.communityList = response.rows
            })
        },
        changeCommunity(raw) {
            if (raw==1) {
                this.$modal.alertError("请选择村社或村");
                return false;
            }
            for (let communityListElement of this.communityList) {
                if(communityListElement.communityId==raw) {
                    this.form.communityName = communityListElement.communityName;
                    break;
                }
            }
            console.log(this.form.communityName)
        },
        changeIsHead(row){
            if (row=='1') this.showHead=true;
            else this.showHead = false;
        },
        selectGrid(value) {//alert(value)
            for (let grids of this.optionsGrids) {
                if(grids.gridId==value) {
                    this.form.gridName = grids.gridName;
                    break;
                }
            }
        },
        changeGrid(id) {
            if (id!='') {
                this.gridVars.communityId=id;
                listGrid(this.gridVars).then(res=>{
                    this.optionsGrids=res.rows;
                    this.form.gridId='';
                    for (let lengthKey=this.optionsGrids.length-1; lengthKey< this.optionsGrids.length;lengthKey--) {
                        this.form.gridId= this.optionsGrids[lengthKey].gridId;
                        this.form.gridName = this.optionsGrids[lengthKey].gridName;
                        break;
                    }
                });
            }
        },
        /** 查询村民列表 */
        getList() {
            this.loading = true;
            listPeople(this.queryParams).then(response => {
                this.peopleList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.girdVisible = false;
            this.restWxOpen = false;
            this.addUser = false;
            this.modifyCommunityDiv = false;
            this.modifyOpen = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {
                peopleId: null,
                openId: null,
                openNickname: null,
                isHead: null,
                headId: null,
                peopleName: null,
                peopleMobile: null,
                peopleCard: null,
                headCard: null,
                headPeopleId:null,
                peopleSex: null,
                peopleBirth: null,
                peopleAddress: null,
                communityId: null,
                gridId: null,
                isParty: null,
                isGrid: 0,
                isCommittee: 0,
                status: null,
                createBy: null,
                createTime: null,
                updateBy: null,
                updateTime: null,
                remark: null
            };
            this.girdForm = {};
            this.resetForm("form");
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.peopleId)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        //查看家庭成员
        handleFamily(row) {
            this.familyVisible = true;
            this.familyVars.peopleId = row.peopleId;
            this.currentFamily = row;
            getFamilyPeople(this.familyVars).then(response=>{
                this.familys = response.rows;
            })

        },
        //查看积分
        handleFamilyScore(row) {
            this.$router.push({path:'/organization/family',query:{s:row.peopleId,t:new Date().getTime()}})
            // let routeData = this.$router.resolve({
            //     name: 'family',
            //     query: {s:row.peopleId,t:new Date().getTime()}
            // });
            // window.open(routeData.href, '_blank')

        },
        //新增家庭成员
        handleAdds(row) {
            this.reset();
            this.form.isHead = 0;
            this.title = "给户主:<b><font color='red'> "+row.peopleName+"</font></b>添加家庭成员";
            // this.open = true;
            this.addUser = true;
            this.form.headCard = row.headCard;
            this.form.headPeopleId = row.peopleId;
            this.form.isGrid='0';
            this.form.isCommittee='0';
            this.form.communityId = row.communityId;
            this.gridVars.communityId=row.communityId;
            listGrid(this.gridVars).then(res=>{
                this.optionsGrids=res.rows;
            });
            this.form.gridId = row.gridId;
            this.form.gridName = row.gridName;
        },
        //变更社区
        modifyCommunity(row) {
            this.reset();
            const peopleId = row.peopleId || this.ids
            this.changeGrid(row.communityId);
            getPeople(peopleId).then(response => {
                this.form = response.data;
                this.form.isGrid = this.form.isGrid.toString();
                this.form.isCommittee = this.form.isCommittee.toString();
                this.gridVars.communityId = this.form.communityId;
                this.modifyCommunityDiv = true;
                this.title = "调整用户:<b><font color='red'> "+row.peopleName+"</font></b>所在社区";
            });
        },
        // 提交变更的社区信息
        doModifyCommunity() {
            const data = {"peopleId":this.form.peopleId,"communityId":this.form.communityId,"gridId":this.form.gridId}
            this.$modal.confirm('确认变更用户社区数据?').then(function () {
                return doSetCommunity(data);
            }).then(() => {
                this.getList();
                this.$modal.msgSuccess("变更成功");
                this.modifyCommunityDiv = false;
            }).catch(() => {
            });
        },
        /** 新增按钮操作 */
        handleAdd(type) {
            this.reset();
            //是户主
            if (type==1) {
                this.form.isHead =1;
                this.title = "添加户主";
            }
            //家庭成员
            else {
                this.form.isHead = 0;
                this.title = "添加家庭成员";
            }
            this.form.isGrid='0';
            this.form.isCommittee='0';
            this.open = true;

        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset();
            const peopleId = row.peopleId || this.ids
            this.changeGrid(row.communityId);
            getPeople(peopleId).then(response => {
                this.form = response.data;
                this.form.isHead= this.form.isHead;
                this.form.isGrid = this.form.isGrid.toString();
                this.form.isCommittee = this.form.isCommittee.toString();
                this.gridVars.communityId = this.form.communityId;
                this.modifyOpen = true;
                this.title = "修改村居民信息";
            });

            // this.gridVars.communityId=id;

        },
        /** 提交按钮 */
        submitForm() {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    if (!isIdCard(this.form.peopleCard)) {
                        this.$modal.alertError("请输入正确身份证号");
                        return false;
                    }
                    if (!isPhone(this.form.peopleMobile)) {
                        this.$modal.alertError("请输入正确的手机号码");
                        return false;
                    }
                    //户主
                    if (this.form.isHead==1) {
                        this.form.headCard = this.form.peopleCard;
                    }
                    if (this.form.peopleId != null) {
                        for (let gridElement of this.optionsGrids) {
                            if (gridElement.gridId == this.form.gridId) {
                                this.form.gridName = gridElement.gridName;
                                break;
                            }
                        }
                            updatePeople(this.form).then(response => {
                            this.$modal.msgSuccess("修改成功");
                            this.cancel();
                            this.getList();
                        });
                    } else {
                        this.communityList.forEach(element=>{
                            if (element.communityId==this.form.communityId) {
                                this.form.communityName=element.communityName;
                                return;
                            }
                        })
                        addPeople(this.form).then(response => {
                            this.$modal.msgSuccess("新增成功");
                            this.cancel();
                            this.getList();
                        });
                    }
                }
            });
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const peopleIds = row.peopleId || this.ids;
            this.$modal.confirm('是否确认删除村民编号为"' + peopleIds + '"的数据项？').then(function () {
                return delPeople(peopleIds);
            }).then(() => {
                this.getList();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => {
            });
        },

        handleAudit(row) {
            const data = {"peopleId":row.peopleId,"status":1}
            this.$modal.confirm('确认审核这条居民数据?').then(function () {
                return auditPeople(data);
            }).then(() => {
                this.getList();
                this.$modal.msgSuccess("审核成功");
            }).catch(() => {
            });
        },
        handleSetHeadCard(row) {
            this.$modal.confirm('确认设置' + row.peopleCard + '为户主?').then(function () {
                return setHeadCard(row);
            }).then(() => {
                this.getList();
                this.$modal.msgSuccess("设置成功");
            }).catch(() => {
            });
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download('organization/people/export', {
                ...this.queryParams
            }, `people_${new Date().getTime()}.xlsx`)

        },
        /** 导入按钮操作 */
        handleImport() {
            this.upload.title = "村居民导入";
            this.upload.open = true;
        },
        handleImportGrid() {
            this.upload.title = "网格员导入";
            this.upload.openGrid = true;
        },
        /** 下载模板操作 */
        importTemplate(type) {
            var  title = '';
            if (type==1) {
                title = '居民资料导入模板_';
            }
            else if(type==2) {
                title = '村民资料导入模板_';
            }
            else if(type==3) {
                title = '社区网格员导入模板_';
            }
            else {
                title = '村网格员导入模板_';
            }
            this.download('organization/people/importTemplate/'+type, {}, title+'.xlsx')
        },
        // 文件上传中处理
        handleFileUploadProgress(event, file, fileList) {
            this.upload.isUploading = true;
        },
        // 文件上传成功处理
        handleFileSuccess(response, file, fileList) {
            this.upload.open = false;
            this.upload.isUploading = false;
            this.$refs.upload.clearFiles();
            this.$alert(response.msg, "导入结果", {dangerouslyUseHTMLString: true});
            this.getList();
        },
        handleGridFileSuccess(response, file, fileList) {
            this.upload.open = false;
            this.upload.openGrid = false;
            this.upload.isUploading = false;
            this.$refs.gridUpload.clearFiles();
            this.$alert(response.msg, "导入结果", {dangerouslyUseHTMLString: true});
            this.getList();
        },
        // 提交上传文件
        submitFileForm() {
            this.$refs.upload.submit();
        },
        gridSubmitFileForm() {
            this.$refs.gridUpload.submit();
        },
        /** 下载村民资料卡 */
        generatePeopleCard(row) {
          this.download('organization/people/generatePeopleCard', {peopleId:row.peopleId}, `村民`+ row.peopleName +`的资料卡_${new Date().getTime()}.jpg`)
        },
        /** 重置网格员微信操作 */
        handleResetWx(row) {
            this.title = "解绑微信,重新绑定网格员身份证";
            this.restWxOpen = true;
            this.form = row;
            this.form.peopleCard = "";
          // const peopleIds = row.peopleId || this.ids;
          // this.$modal.confirm('是否确认重置村民编号为"' + row.peopleName + '"的微信数据？').then(function () {
          //   return resetPeopleWx(peopleIds);
          // }).then(() => {
          //   this.getList();
          //   this.$modal.msgSuccess("解绑成功");
          // }).catch(() => {
          //   this.$modal.msgError("解绑成功");
          // });
        },
        /** 重置村民微信操作 */
        handleCommonResetWx(row) {
            // this.title = "解绑微信,重新绑定身份证";
            // this.restWxOpen = true;
            // this.form = row;
            // this.form.peopleCard = "";
            // const peopleIds = row.peopleId || this.ids;
            this.$modal.confirm('是否确认解绑村民"' + row.peopleName + '"的微信数据？').then(function () {
              return resetCommonPeopleWx(row);
            }).then(() => {
              this.getList();
              this.$modal.msgSuccess("解绑成功");
            }).catch(() => {
              this.$modal.msgError("解绑成功");
            });
        },
        submitRestWxForm() {
            this.$refs["restWxForm"].validate(valid => {
                console.log(this.form)
                if (valid) {
                    resetPeopleWx(this.form).then(response => {
                        this.$modal.msgSuccess("网格员微信解绑成功");
                        this.restWxOpen = false;
                        this.getList();
                    });
                }
            });
        }
    }
};
</script>
